import _area from '@/assets/json/vue-area'
export default {
  getProvinces(){
    var provinces = [];
    for(var i=0;i<_area.provinces.length;i++){
      provinces[i] = { value:_area.provinces[i].code, label:_area.provinces[i].name,parent:_area.provinces[i].parentId};
    }
    return provinces;
  },
  getCitysAll(){
    var citys = [];
    for(var i=0;i<_area.citys.length;i++){
      citys[i] = { value:_area.citys[i].code, label: _area.citys[i].name,parent:_area.citys[i].parentId};
    }
    return citys;
  },
  getCitys(parent){
    var citys = [];
    var j=0;
    //遍历所有的城市
    for(var i=0;i<_area.citys.length;i++){
      // console.log(_area.citys[i])
      if(_area.citys[i].parentId==parent){
        citys[j] = { value:_area.citys[i].code, label: _area.citys[i].name,parent:_area.citys[i].parentId};
        j++;
      }else{
        if(parent==110000){
          citys[j] = { value:110000, label: "北京市",parent:0};
          return citys;
        }else if(parent==120000){
          citys[j] = { value:120000, label:"天津市",parent:0};
          return citys;
        }
      }
    }
    return citys;
  }
}
